﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.Core;
using Microhard.Core.DBUtility;

namespace Microhard.WarehouseInsp.WebUI.Areas.WarehouseInsp.Models
{
    public static class HtmlExtension
    {
        public static List<SelectListItem> GetProductList(this HtmlHelper helper)
        {
            List<SelectListItem> result = new List<SelectListItem>();
            IProductList list = IoC.Resolve<IProductList>();
            var data = list.Query(null);
            if (data != null)
            {
                foreach (var d in data)
                {
                    result.Add(new SelectListItem
                    {
                        Text = d.Name,
                        Value = d.ProductID.ToString()
                    });
                }
            }
            return result;
        }

        public static List<SelectListItem> GetWarehouse(this HtmlHelper helper)
        {
            List<SelectListItem> result = new List<SelectListItem>();
            IWarehouse list = IoC.Resolve<IWarehouse>();
            var data = list.Query(null);
            if (data != null)
            {
                foreach (var d in data)
                {
                    result.Add(new SelectListItem
                    {
                        Text = d.Name,
                        Value = d.WarehouseID.ToString()
                    });
                }
            }
            return result;
        }

        public static List<SelectListItem> GetProductList(this HtmlHelper helper, Guid OutInPutApplyID)
        {

            List<SelectListItem> result = new List<SelectListItem>();
            IOutIntPutWarehouse warehouse = IoC.Resolve<IOutIntPutWarehouse>();
            var v = warehouse.GetOutRecordByApplyID(OutInPutApplyID);
            if (v != null && v.Count > 0)
            {
                foreach (var s in v)
                {
                    result.Add(new SelectListItem { Text = s.ProductName, Value = s.PPInRecord.ProductID.ToString() });
                }
            }

            return result;
        }

        /// <summary>
        /// 得到已入库的产品列表
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="OutInPutWarehouseID"></param>
        /// <returns></returns>
        public static List<SelectListItem> GetApplyProductList(this HtmlHelper helper, Guid ProjectID)
        {
            List<SelectListItem> result = new List<SelectListItem>();
            IOutIntPutWarehouse warehouse = IoC.Resolve<IOutIntPutWarehouse>();
            var v = warehouse.GetInRecordByProject(ProjectID);

            if (v != null && v.Count > 0)
            {
                foreach (var o in v)
                    result.Add(new SelectListItem { Text = o.PPInRecord.Product.Name, Value = o.PlnPdgID.ToString() });
            }

            return result;
        }
    }

}